﻿using System;
using GigaSite.Domain.Entities;
using GigaSite.Domain.Enums;
using Newtonsoft.Json;

namespace GigaSite.Web.Areas.ControlPanel.Models
{
    /// <summary>
    /// Модель компании
    /// </summary>
    public class CompanyModel
    {
        /// <summary>
        /// Идентификатор компании
        /// </summary>
        [JsonProperty("id")]
        public long Id { get; set; }

        /// <summary>
        /// Отображаемое имя
        /// </summary>
        [JsonProperty("displayName")]
        public string DisplayName { get; set; }

        /// <summary>
        /// Системное имя
        /// </summary>
        [JsonProperty("systemName")]
        public string SystemName { get; set; }

        /// <summary>
        /// Тип компании
        /// </summary>
        [JsonProperty("companyType")]
        public string CompanyType { get; set; }

        /// <summary>
        /// Идентификатор типа компании
        /// </summary>
        [JsonProperty("companyTypeId")]
        public short CompanyTypeId { get; set; }

        /// <summary>
        /// Описание компании
        /// </summary>
        [JsonProperty("description")]
        public string Description { get; set; }

        /// <summary>
        /// Логотип
        /// </summary>
        [JsonProperty("logoImage")]
        public string LogoImage { get; set; }

        /// <summary>
        /// Скрыта
        /// </summary>
        [JsonProperty("hidden")]
        public bool Hidden { get; set; }

        /// <summary>
        /// Рейтинг компании
        /// </summary>
        [JsonProperty("rating")]
        public int Rating { get; set; }

        /// <summary>
        /// Количество просмотров
        /// </summary>
        [JsonProperty("views")]
        public long Views { get; set; }

        /// <summary>
        /// Компания является новой
        /// </summary>
        [JsonProperty("new")]
        public bool New { get; set; }

        /// <summary>
        /// Компания является горячей - популярной
        /// </summary>
        [JsonProperty("hot")]
        public bool Hot { get; set; }

        /// <summary>
        /// Email
        /// </summary>
        [JsonProperty("email")]
        public string Email { get; set; }

        /// <summary>
        /// Web сайт
        /// </summary>
        [JsonProperty("website")]
        public string WebSite { get; set; }

        /// <summary>
        /// Контактные телефоны
        /// </summary>
        [JsonProperty("phones")]
        public string Phones { get; set; }

        /// <summary>
        /// Сведения о времени работы
        /// </summary>
        [JsonProperty("worktime")]
        public string WorktimeInfo { get; set; }

        /// <summary>
        /// Дата создания
        /// </summary>
        [JsonProperty("dateCreated")]
        public DateTime? DateCreated { get; set; }

        /// <summary>
        /// Дата редактирования
        /// </summary>
        [JsonProperty("dateModified")]
        public DateTime? DateModified { get; set; }

        /// <summary>
        /// Город
        /// </summary>
        [JsonProperty("city")]
        public string City { get; set; }

        /// <summary>
        /// Количество посетителей магазина
        /// </summary>
        [JsonProperty("visitors")]
        public int VisitorsCount { get; set; }

        /// <summary>
        /// Количество товаров
        /// </summary>
        [JsonProperty("goods")]
        public int GoodsCount { get; set; }

        /// <summary>
        /// Количество услуг
        /// </summary>
        [JsonProperty("services")]
        public int ServicesCount { get; set; }

        /// <summary>
        /// Простой конструктор
        /// </summary>
        public CompanyModel()
        {
        }

        /// <summary>
        /// Инициализирует модель на основе доменного объекта
        /// </summary>
        /// <param name="company"></param>
        public CompanyModel(Company company)
        {
            Id = company.Id;
            DisplayName = company.DisplayName;
            Description = company.Description;
            CompanyType = company.CompanyType.GetEnumMemberName();
            SystemName = company.SystemName;
            LogoImage = company.LogoImage;
            Views = company.Views;
            Rating = company.Rating;
            Hot = company.Hot;
            New = company.New;
            Email = company.Email;
            WebSite = company.WebSite;
            Phones = company.Phones;
            WorktimeInfo = company.WorktimeInfo;
            DateCreated = company.DateCreated;
            DateModified = company.DateModified;
            City = company.City.DisplayName;
            Hidden = company.Hidden;
            VisitorsCount = company.CompanyVisitors.Count;
            GoodsCount = company.Goods.Count;
            ServicesCount = company.Services.Count;
            CompanyTypeId = (short) company.CompanyType;
        }
    }
}